ia64: Enhance vt-d support for ia64.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 17 Feb 2009 11:10:00 +0000 (11:10 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 17 Feb 2009 11:10:00 +0000 (11:10 +0000)
This patch targets for enhancing vt-d support for ia64.
1. reserve enough memory for building dom0 vt-d page table.
2. build 1:1 vt-d page table according to system's mem map.
3. enable vt-d interrupt support for ia64.

Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Acked-by: Isaku Yamahata <yamahata@valinux.co.jp>
xen/arch/ia64/xen/domain.c
xen/drivers/passthrough/vtd/ia64/vtd.c
xen/drivers/passthrough/vtd/iommu.c
xen/drivers/passthrough/vtd/x86/vtd.c
xen/include/asm-ia64/hvm/iommu.h
xen/include/xen/iommu.h

index ed98f8f5628eb6638de95e13c92175f7f212e036..33789f2b55868c340d17ae168499be74a361877a 100644 (file)
@@ -2023,6 +2023,7 @@ static void __init calc_dom0_size(void)
        unsigned long p2m_pages;
        unsigned long spare_hv_pages;
        unsigned long max_dom0_size;
+       unsigned long iommu_pg_table_pages = 0;
 
        /* Estimate maximum memory we can safely allocate for dom0
         * by subtracting the p2m table allocation and a chunk of memory
@@ -2033,8 +2034,13 @@ static void __init calc_dom0_size(void)
        domheap_pages = avail_domheap_pages();
        p2m_pages = domheap_pages / PTRS_PER_PTE;
        spare_hv_pages = 8192 + (domheap_pages / 4096);
-       max_dom0_size = (domheap_pages - (p2m_pages + spare_hv_pages))
-                        * PAGE_SIZE;
+
+       if (iommu_enabled)
+               iommu_pg_table_pages = domheap_pages * 4 / 512;
+               /* There are 512 ptes in one 4K vtd page. */
+
+       max_dom0_size = (domheap_pages - (p2m_pages + spare_hv_pages) -
+                       iommu_pg_table_pages) * PAGE_SIZE;
        printk("Maximum permitted dom0 size: %luMB\n",
               max_dom0_size / (1024*1024));
 
index ca0e116f3c50d900d8bfe6e3760016c1adb9847a..9958ce2bbe00f1b7af9fbea31e4a85085a06823e 100644 (file)
@@ -114,3 +114,33 @@ void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
 {
     /* dummy */
 }
+
+static int do_dom0_iommu_mapping(unsigned long start, unsigned long end,
+                               void *arg)
+{
+    unsigned long tmp, pfn, j, page_addr = start;
+    struct domain *d = (struct domain *)arg;
+
+    extern int xen_in_range(paddr_t start, paddr_t end);
+    /* Set up 1:1 page table for dom0 for all Ram except Xen bits.*/
+
+    while (page_addr < end)
+    {
+       if (xen_in_range(page_addr, page_addr + PAGE_SIZE))
+            continue;
+
+        pfn = page_addr >> PAGE_SHIFT;
+        tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
+        for ( j = 0; j < tmp; j++ )
+            iommu_map_page(d, (pfn*tmp+j), (pfn*tmp+j));
+
+       page_addr += PAGE_SIZE;
+    }
+    return 0;
+}
+
+void iommu_set_dom0_mapping(struct domain *d)
+{
+       BUG_ON(d != dom0);
+       efi_memmap_walk(do_dom0_iommu_mapping, d);
+}
index 386b0f9a169ce31282001aba9360c4a9bf37643d..d5831873f56062eac5eb0d494fb3c0e76909e3c8 100644 (file)
@@ -30,6 +30,7 @@
 #include <xen/pci.h>
 #include <xen/pci_regs.h>
 #include <xen/keyhandler.h>
+#include <asm/msi.h>
 #include "iommu.h"
 #include "dmar.h"
 #include "extern.h"
@@ -829,7 +830,6 @@ static void dma_msi_data_init(struct iommu *iommu, int vector)
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 }
 
-#ifdef SUPPORT_MSI_REMAPPING
 static void dma_msi_addr_init(struct iommu *iommu, int phy_cpu)
 {
     u64 msi_address;
@@ -846,12 +846,6 @@ static void dma_msi_addr_init(struct iommu *iommu, int phy_cpu)
     dmar_writel(iommu->reg, DMAR_FEUADDR_REG, (u32)(msi_address >> 32));
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 }
-#else
-static void dma_msi_addr_init(struct iommu *iommu, int phy_cpu)
-{
-    /* ia64: TODO */
-}
-#endif
 
 static void dma_msi_set_affinity(unsigned int vector, cpumask_t dest)
 {
@@ -988,7 +982,6 @@ static int intel_iommu_domain_init(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct iommu *iommu = NULL;
-    u64 i, j, tmp;
     struct acpi_drhd_unit *drhd;
 
     drhd = list_entry(acpi_drhd_units.next, typeof(*drhd), list);
@@ -1000,17 +993,8 @@ static int intel_iommu_domain_init(struct domain *d)
     {
         extern int xen_in_range(paddr_t start, paddr_t end);
 
-        /* Set up 1:1 page table for dom0 for all RAM except Xen bits. */
-        for ( i = 0; i < max_page; i++ )
-        {
-            if ( !page_is_conventional_ram(i) ||
-                 xen_in_range(i << PAGE_SHIFT, (i + 1) << PAGE_SHIFT) )
-                continue;
-
-            tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
-            for ( j = 0; j < tmp; j++ )
-                iommu_map_page(d, (i*tmp+j), (i*tmp+j));
-        }
+        /* Set up 1:1 page table for dom0 */
+        iommu_set_dom0_mapping(d);
 
         setup_dom0_devices(d);
         setup_dom0_rmrr(d);
index 18ff1187fde724fb2517ff2370575de11c9f0eab..5b631bbdb0198df0683f8a0c8d60057ec2795a8a 100644 (file)
@@ -143,3 +143,23 @@ void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
     }
     spin_unlock(&d->event_lock);
 }
+
+void iommu_set_dom0_mapping(struct domain *d)
+{
+    u64 i, j, tmp;
+    extern int xen_in_range(paddr_t start, paddr_t end);
+
+    BUG_ON(d != dom0);
+
+    for ( i = 0; i < max_page; i++ )
+    {
+        /* Set up 1:1 mapping for dom0 for all RAM except Xen bits. */
+        if ( !page_is_conventional_ram(i) ||
+             xen_in_range(i << PAGE_SHIFT, (i + 1) << PAGE_SHIFT) )
+            continue;
+
+        tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
+        for ( j = 0; j < tmp; j++ )
+            iommu_map_page(d, (i*tmp+j), (i*tmp+j));
+    }
+}
index b33ee457f6aeca5ea8bc560a2d063de01a7c11e3..9a14a31dff92f49e4a188962ff73516eedd6a7c7 100644 (file)
@@ -6,6 +6,7 @@
 #include <public/arch-ia64/hvm/save.h>
 #include <asm/linux/asm/hw_irq.h>
 #include <asm/linux-xen/asm/iosapic.h>
+#include <asm/hw_irq.h>
 
 struct iommu_ops;
 extern struct iommu_ops intel_iommu_ops;
index 8cf3ded2a9f1ee4a9ccad6d8cd93e06112dca3c1..c56b33d4ad5418b715e5a21187179cc7a7eb02c6 100644 (file)
@@ -114,4 +114,6 @@ void iommu_update_ire_from_msi(struct msi_desc *msi_desc, struct msi_msg *msg);
 void iommu_suspend(void);
 void iommu_resume(void);
 
+void iommu_set_dom0_mapping(struct domain *d);
+
 #endif /* _IOMMU_H_ */